package com.example.weathermvvm.util

import com.example.weathermvvm.data.PlaceRepository
import com.example.weathermvvm.data.WeatherRepository
import com.example.weathermvvm.data.db.WeatherDatabase
import com.example.weathermvvm.data.network.api.WeatherNetwork
import com.example.weathermvvm.ui.MainModelFactory
import com.example.weathermvvm.ui.area.ChooseAreaModelFactory
import com.example.weathermvvm.ui.weather.WeatherModelFactory

/**
 *
 * @Author： LJH
 * @Time： 2022/8/10
 * @description：viewModel工厂对象注入工具类
 */
object InjectorUtil {
    /**
     * 获取 PlaceRepository
     * @return PlaceRepository
     */
    private fun getPlaceRepository() = PlaceRepository.getInstance(WeatherDatabase.getPlaceDao(),
        WeatherNetwork.getInstance())

    fun getChooseAreaModelFactory() = ChooseAreaModelFactory(getPlaceRepository())

    /**
     * 获取天气 WeatherRepository
     * @return WeatherRepository
     */
    private fun getWeatherRepository() = WeatherRepository.getInstance(
        WeatherDatabase.getWeatherDao(), WeatherNetwork.getInstance())

    fun getMainModelFactory() = MainModelFactory(getWeatherRepository())

    fun getWeatherModelFactory() = WeatherModelFactory(getWeatherRepository())
}